package examples
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	
	import com.wskeee.ec.components.Button;
	import com.wskeee.ec.components.ComboBox;
	import com.wskeee.ec.components.Label;
	import com.wskeee.ec.containers.Container;
	import com.wskeee.ec.containers.GridBox;
	import com.wskeee.ec.containers.VBox;

	public class ComboBoxExample
	{
		public static function createComboBox():Container
		{
			var mainBox:VBox = new VBox();
			var head:Label = new Label();
			head.text = "ComboBox";
			mainBox.verticalGap = 20;
			mainBox.paddingTop = mainBox.paddingBottom = mainBox.paddingLeft = mainBox.paddingRight = 5;
			mainBox.addChild(head);
			
			var selectedLabel:Label = new Label();
			selectedLabel.text = "label: "+" value: ";
			
			mainBox.addChild(selectedLabel);
			
			var combo:ComboBox = new ComboBox();
			combo.width = 150;
			combo.addEventListener(Event.CHANGE,function(evt:Event):void
			{
				if(combo.selectedItem)
					selectedLabel.text = "label: "+combo.selectedItem.label+" value: "+combo.selectedItem.value;
			});
			function createListForNum(value:int):void
			{
				var ds:Vector.<Object> = new Vector.<Object>(value);
				for(var i:int=0;i<value;i++)
					ds[i] = {label:"wskeee"+i,value:i*1000};	
				combo.dataProvider = ds;
				combo.selectedIndex = 0;
			}
			mainBox.addChild(combo);
			//---------------------
			//control
			//---------------------
			var controlBox:GridBox = new GridBox(3);
			controlBox.autoSize = true;
			var button:Button = new Button();
			button.label = "重新赋值";
			button.addEventListener(MouseEvent.CLICK,function(evt:MouseEvent):void
			{
				createListForNum(int(listTxt.text));
				combo.open();
			});
			var listTxt:TextField = new TextField();
			listTxt.type = TextFieldType.INPUT;
			listTxt.multiline = false;
			listTxt.border = true;
			listTxt.width = 30;
			listTxt.height = 20;
			listTxt.text = "4";
			
			controlBox.addChild(button);
			controlBox.addChild(listTxt);
			
			mainBox.addChild(controlBox);
			
			createListForNum(1);
			return mainBox;
		}
	}
}